package com.itheima.domain;

public class Student implements Comparable<Student> {

    private String name;
    private int yuwen;
    private int shuxue;
    private int yingyu;

    public Student() {
    }

    public Student(String name, int yuwen, int shuxue, int yingyu) {
        this.name = name;
        this.yuwen = yuwen;
        this.shuxue = shuxue;
        this.yingyu = yingyu;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getYuwen() {
        return yuwen;
    }

    public void setYuwen(int yuwen) {
        this.yuwen = yuwen;
    }

    public int getShuxue() {
        return shuxue;
    }

    public void setShuxue(int shuxue) {
        this.shuxue = shuxue;
    }

    public int getYingyu() {
        return yingyu;
    }

    public void setYingyu(int yingyu) {
        this.yingyu = yingyu;
    }

    public int getZongfen() {
        return yuwen + shuxue + yingyu;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", yuwen=" + yuwen +
                ", shuxue=" + shuxue +
                ", yingyu=" + yingyu +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        //根据总分比较
        int result = o.getZongfen() - this.getZongfen();
        result = result == 0 ? o.yuwen - this.yuwen : result;
        result = result == 0 ? o.shuxue - this.shuxue : result;
        result = result == 0 ? o.name.compareTo(this.name) : result;

        return result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (yuwen != student.yuwen) return false;
        if (shuxue != student.shuxue) return false;
        if (yingyu != student.yingyu) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

    //一个简单的算法  hash算法
    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = result * 31 + yuwen;
        result = result * 31 + shuxue;
        result = result * 31 + yingyu;
        return result;
    }
}
